package myJs.implicits

import org.scalajs.dom.Element

import scala.scalajs.js
import scala.scalajs.js.JSON
import scala.scalajs.js.JSConverters._
import myJs.Implicits._

/**
 * Created by Administrator on 2020/1/16
 */
trait MyJDAnT {

  implicit class MyJDAn(jd: js.Dictionary[js.Any]) {

    def myGet(key: String) = jd.getOrElse(key, "").toString

    def myGetDouble(key: String) = jd.getOrElse(key, "").toString.toDouble

    def myGetInt(key: String) = jd.getOrElse(key, "").toString.toInt

    def toMyJDS={
      jd.map { case (k, v) =>
        val trueV = if (v == null) "" else v.toString
        (k, trueV)
      }.toJSDictionary
    }

    def toSeqMap = {
      jd.toList.toSeqMap
    }

  }

  implicit class MyJDS(jd: js.Dictionary[String]) {

    def jsonStr = JSON.stringify(jd)

    def toSeqMap = {
      jd.toList.toSeqMap
    }

  }

}
